package cn.yudao.ymcc.utils;


import cn.yudao.ymcc.dto.UserInfoParamDto;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityGetUserInfoUtil {

    public static UserInfoParamDto getUserInfoParamDto(){
        // 获取上下文对象
        SecurityContext context = SecurityContextHolder.getContext();
        // 得到用户信息
        Authentication authentication = context.getAuthentication();
        // 得到存储的username--（其实存了个json字符串）
        Object principal = authentication.getPrincipal();
        AssertUtil.isNotNull(principal,"非法异常");
        UserInfoParamDto userInfoParamDto = JSONObject.parseObject(principal.toString(), UserInfoParamDto.class);
        return userInfoParamDto;
    }


}
